worker: use correct ctor for error serialization#25951
Closed
addaleax wants to merge 1 commit intonodejs:masterfrom
Closed
worker: use correct ctor for error serialization#25951addaleax wants to merge 1 commit intonodejs:masterfrom
addaleax wants to merge 1 commit intonodejs:masterfrom
Conversation
When serializing errors, use the error constructor that is closest to the object itself in the prototype chain. The previous practice of walking downwards meant that `Error` would usually be the first constructor that is used, even when a more specific one would be available/appropriate, because it is the base class of the other common error types.
jasnell
approved these changes
Feb 6, 2019
devsnek
approved these changes
Feb 6, 2019
gengjiawen
reviewed
Feb 6, 2019
| ObjectPrototypeToString(error) === '[object Error]') { | ||
| const constructors = GetConstructors(error); | ||
| for (var i = constructors.length - 1; i >= 0; i--) { | ||
| for (var i = 0; i < constructors.length; i++) { |
Member
There was a problem hiding this comment.
Maybe for (const name of constructors) ?
Member
Author
There was a problem hiding this comment.
@gengjiawen The idea here is that this code is supposed to be as robust against monkey-patching as possible, because we do not want to generate more exceptions while attempting to handle another exception – with for (const … of …), it’s possible to override Array.prototype[Symbol.iterator]() and give false results or throw another exception.
benjamingr
approved these changes
Feb 6, 2019
JungMinu
approved these changes
Feb 6, 2019
cjihrig
approved these changes
Feb 6, 2019
Member
Author
Member
Author
|
Landed in de9d5ff |
addaleax
added a commit
that referenced
this pull request
Feb 8, 2019
When serializing errors, use the error constructor that is closest to the object itself in the prototype chain. The previous practice of walking downwards meant that `Error` would usually be the first constructor that is used, even when a more specific one would be available/appropriate, because it is the base class of the other common error types. PR-URL: #25951 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
addaleax
added a commit
that referenced
this pull request
Feb 8, 2019
When serializing errors, use the error constructor that is closest to the object itself in the prototype chain. The previous practice of walking downwards meant that `Error` would usually be the first constructor that is used, even when a more specific one would be available/appropriate, because it is the base class of the other common error types. PR-URL: #25951 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
3 tasks
Merged
This was referenced Feb 15, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When serializing errors, use the error constructor that is
closest to the object itself in the prototype chain.
The previous practice of walking downwards meant that
Errorwould usually be the first constructor that is used,even when a more specific one would be available/appropriate,
because it is the base class of the other common error types.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes